﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Jzy.Model.Project;
using Jzy.DAL.Project;
using System.Data;

using Frame.Lib.Core.Base;
using Frame.Lib.Core.Attach;
using Frame.Lib.Core.Dict;
using Frame.Lib.Enums;

namespace Jzy.BLL.Project
{
    public class PrjBugBO : CommonOperate<PrjBugInfo>
    {
        private PrjBugDAL _prjBug;
        protected override BaseDAL DAL
        {
            get
            {
                return _prjBug;
            }
        }
        public PrjBugBO()
            : base("PrjBug")
        {
            _prjBug = new PrjBugDAL();
        }

        /// <summary>
        /// 获得某个人登记的bug列表，不包括已归档项目
        /// </summary>
        /// <param name="creatorID"></param>
        /// <returns></returns>
        public List<PrjBugInfo> GetRegistList(int status, int creatorID)
        {
            List<PrjBugInfo> list = _prjBug.GetRegistList(status, creatorID);
            AddTypeName(list);
            return list;
        }

        /// <summary>
        /// 获得待处理列表
        /// </summary>
        /// <param name="Status"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public List<PrjBugInfo> GetDoList(int status, int userID)
        {
            List<PrjBugInfo> list = _prjBug.GetDoList(status, userID);
            AddTypeName(list);
            return list;
        }

        public void BindPrj(System.Web.UI.WebControls.DropDownList drpPrj)
        {
            //ProjectBO prj = new ProjectBO();
            DataTable dt = _prjBug.GetNoArchivePrj();

            foreach (DataRow dr in dt.Rows)
            {
                System.Web.UI.WebControls.ListItem item = new System.Web.UI.WebControls.ListItem();
                item.Text = dr["Name"] + " ( " + dr["PMName"] + " )";
                item.Value = dr["ID"].ToString();
                drpPrj.Items.Add(item);
            }

        }


        public override PrjBugInfo GetInfo(object id)
        {
            PrjBugInfo info = base.GetInfo(id);
            if (id != null)
            {
                info.GetPictures = prjID => (new ImageBO("PrjBugPicture")).GetList(prjID, null);
            }
            return info;
        }


        public void SetColorByStatus(System.Web.UI.WebControls.Label lblStatus, BugStatus status)
        {
            switch (status)
            {
                case BugStatus.处理中:
                    lblStatus.Style.Add("color", "Green");
                    break;
                case BugStatus.新的:
                case BugStatus.重新打开:
                    lblStatus.Style.Add("color", "Red");
                    break;
                case BugStatus.已解决:
                    lblStatus.Style.Add("color", "Blue");
                    break;
            }
        }

        public DataTable GetSelectData(string strSelectIDs)
        {
            DataTable dt = _prjBug.GetSelectData(strSelectIDs);
            DictBO dict = new DictBO();
            dict.AddName(dt, DictItem.缺陷类型, "TypeName", "TypeCode");
            return dt;
        }

        public List<PrjBugInfo> GetListByProject(string PrjID, int Status)
        {
            List<PrjBugInfo> list = _prjBug.GetListByProject(PrjID, Status);

            AddTypeName(list);

            return list;
        }

        private void AddTypeName(List<PrjBugInfo> list)
        {
            DictBO dict = new DictBO();
            dict.SetName<PrjBugInfo>(list, DictItem.缺陷类型, "TypeName", "TypeCode");
        }
    }
}
